package cn.wolfcode.p2p.base.service.impl;

import cn.wolfcode.p2p.base.domain.Account;
import cn.wolfcode.p2p.base.exception.DisplayableException;
import cn.wolfcode.p2p.base.mapper.AccountMapper;
import cn.wolfcode.p2p.base.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by wolfcode on 2018/7/23.
 */
@Service@Transactional
public class AccountServiceImpl implements IAccountService {
    @Autowired
    private AccountMapper accountMapper;
    public int save(Account account) {
        return accountMapper.insert(account);
    }

    public int update(Account account) {
        int count = accountMapper.updateByPrimaryKey(account);
        if(count==0){
            System.out.println("乐观锁异常,accountId:"+account.getId());
            throw new DisplayableException("系统繁忙,请重试");
        }
        return 0;
    }

    public Account get(Long id) {
        return accountMapper.selectByPrimaryKey(id);
    }
}
